/**
 * 
 */

define(['angular'], function (angular) {
    'use strict';
//	console.log('三模块通用过滤器启动');
//return angular.module('app.filters', []);
	angular.module('app.filters', [])
	/*
	.filter('myfilter', function() {  
	   return function(input, param1) {  
		      console.log("------------------------------------------------- begin dump of custom parameters");  
		      console.log("input=",input);  
		      console.log("param1(string)=", param1);  
		      var args = Array.prototype.slice.call(arguments);  
		      console.log("arguments=", args);  
		      console.log("arguments=", args.length);  
		      if (3<=args.length) {  
		           console.log("param2(string)=", args[2]);  
		      }  
		      if (4<=args.length) {  
		           console.log("param3(bool)=", args[3]);  
		      }  
		      console.log("------------------------------------------------- end dump of custom parameters");  
		      // filter  
		      if (5<=args.length) {  
		    	  console.log('args[4]-->',args[4]);
		          return window[args[4]](input);  
//		          return args[4](input);  
		      }  
		      
		      return input;  
		   };  
		 });
	*/
	
	.filter('myfilter', function() {  
	   return function(input, param1) {  
		   /*
	      console.log("------------------------------------------------- begin dump of custom parameters");  
	      console.log("input=",input);  
	      console.log("param1(string)=", param1);  
	      var args = Array.prototype.slice.call(arguments);  
	      console.log("arguments=", args);  
	      console.log("arguments=", args.length);  
	      if (3<=args.length) {  
	           console.log("param2(string)=", args[2]);  
	      }  
	      if (4<=args.length) {  
	           console.log("param3(bool)=", args[3]);  
	      }  
	      console.log("------------------------------------------------- end dump of custom parameters");  
	      */
	      
	      // filter  
	      /*
		      if (5<=args.length) {  
		    	  console.log('args[4]-->',args[4]);
		          return window[c](input);  
//		          return args[4](input);  
		      }  
		      */
	      return input;  
	   };  
	 })
		 
	.filter('toKbfilter', function() {  
	   return function(input, param1) {  
		  /* 
	      console.log("------------------------------------------------- begin dump of custom parameters");  
	      console.log("input=",input);  
	      console.log("param1(string)=", param1);  
	      var args = Array.prototype.slice.call(arguments);  
	      console.log("arguments=", args);  
	      console.log("arguments=", args.length);  
	      if (3<=args.length) {  
	           console.log("param2(string)=", args[2]);  
	      }  
	      if (4<=args.length) {  
	           console.log("param3(bool)=", args[3]);  
	      }  
	      console.log("------------------------------------------------- end dump of custom parameters");  
	      */
	      // filter  
	      
	      if (input!=0) {  
		      /*
		      var output = [];  
		      angular.forEach(input, function(v,k){  
		           if (v.phone.contains("555")) {  
		                output.push(v);  
		           }  
		      });
		      */
		      
		      //KB
		      var output = input / 1024;
		      console.log()
		      if(output>=1000){
			      //MB
			      output = output / 1024;
			      if(output>=1000){
				      //GB
				      output = output / 1024;
				      output = output.toFixed(2) + ' GB';
			      }else{
			    	  output = output.toFixed(2) + ' MB';
			      }
		      }else{
		    	  output = output.toFixed(2) + ' KB';
		      }
		      
		      return output;       
	      }else{
	    	  return '0 KB';
	      }
	      
	      return input;  
	   };  
	 })
	 
	//调用实例:        {{row.sTitle.value | textCut:true:15:' ...'}}
	.filter('textCut', function () {
	    return function (value, wordwise, max, tail) {
	        if (!value) return '';
	
	        max = parseInt(max, 10);
	        if (!max) return value;
	        if (value.length <= max) return value;
	
	        value = value.substr(0, max);
	        if (wordwise) {
	            var lastspace = value.lastIndexOf(' ');
	            if (lastspace != -1) {
	                value = value.substr(0, lastspace);
	            }
	        }
	
	        return value + (tail || ' …');
	    };
	})		
	
	//AngularJs的百分数过滤器
	.filter('PercentValue', function () {
	    return function (o) {
	        if (o != undefined && /(^(-)*\d+\.\d*$)|(^(-)*\d+$)/.test(o)) {
	            var v = parseFloat(o);
	            return Number(Math.round(v * 10000) / 100).toFixed(2) + "%";
	        } else {
	            //return "undefined";
	            return "";
	        }
	    }
	})
	
	//AngularJs的 ng-bind-html unsafe过滤器
	.filter('toTrusted', ['$sce', function ($sce) {
	    return function (text) {
	        return $sce.trustAsHtml(text);
	    }
	}])
	
	;
	
 });